var Enemy = function(t, e, i, a) {
    this.id = a,
    this.enemytype = i,
    Phaser.Sprite.call(this, game, 0, 0, this.enemytype),
    this.punchSound = game.add.audio("man-punch", FrauenVsRefugees.VOLUME, !1),
    this.hitSound = game.add.audio("man-hit", FrauenVsRefugees.VOLUME, !1),
    this.kickHitSound = game.add.audio("man-kick-hit", FrauenVsRefugees.VOLUME, !1),
    this._position3D = {
        x: t,
        y: 0,
        z: e - .001
    },
    this.updatePosition(),
    this.shadow = game.add.sprite(0, 0, "shadow"),
    this.shadow.anchor.set(.5, 1),
    FrauenVsRefugees.Game.singleton.addShadow(this.shadow),
    Enemy.enemies[this.name + this.id] = this,
    this.anchor.set(.5, 1),
    this.createAnimations(),
    this.idleAnimation.play(),
    this.direction = 1,
    this.scale.set(1, 1),
    this.wanderingDirection = new Phaser.Point(this.WanderingSpeed.x,this.WanderingSpeed.y),
    this.wanderingTimer = null ,
    this.canStartMoving = !1
}
;
Enemy.prototype = Object.create(Phaser.Sprite.prototype),
Enemy.prototype.constructor = Enemy,
Enemy.prototype.createAnimations = function() {
    console.error("createAnimations should be overwriten by a child class")
}
,
Enemy.prototype.updateState = function(t) {
    if (this.currentState != t)
        switch (this.currentState = t,
        this.currentState) {
        case Enemy.States.idle:
        default:
            this.idleAnimation.play();
            break;
        case Enemy.States.hunting:
            this.huntingAnimation.play(),
            this.startWanderingTimer();
            break;
        case Enemy.States.wandering:
            this.huntingAnimation.play();
            var e = Math.random() < .5 ? -1 : 1
              , i = Math.random() < .5 ? -1 : 1;
            this.wanderingDirection.x = this.WanderingSpeed.x * e,
            this.wanderingDirection.y = this.WanderingSpeed.y * i,
            this.startWanderingTimer();
            break;
        case Enemy.States.punching:
            this.destroyWanderingTimer(),
            this.punchingAnimation.play(),
            game.time.events.add(250, this.hitFrau, this);
            break;
        case Enemy.States.gothit:
            this.destroyWanderingTimer(),
            this.gotHitAnimation.play();
            break;
        case Enemy.States.gotkick:
            this.destroyWanderingTimer(),
            this.gotKickAnimation.play(),
            this.currentState = Enemy.States.gothit;
            break;
        case Enemy.States.gameover:
            var a = game.add.audio("man-fall", FrauenVsRefugees.VOLUME, !1);
            FrauenVsRefugees.SoundManager.play(this.hitSound, 100),
            FrauenVsRefugees.SoundManager.play(a, 100),
            this.destroyWanderingTimer(),
            this.gameoverAnimation.play();
            var e = 30 * this.scale.x
              , s = this.game.add.tween(this._position3D).to({
                x: this._position3D.x + e,
                y: this._position3D.y - 25
            }, 400, Phaser.Easing.Sinusoidal.Out)
              , n = this.game.add.tween(this._position3D).to({
                y: this._position3D.y
            }, 250, Phaser.Easing.Sinusoidal.In);
            s.chain(n),
            s.start()
        }
}
,
Enemy.prototype.changeWalkingType = function() {
    this.destroyWanderingTimer(),
    this.currentState = Enemy.States.none,
    this.updateState(Math.random() < .5 ? Enemy.States.wandering : Enemy.States.hunting)
}
,
Enemy.prototype.startWanderingTimer = function() {
    this.destroyWanderingTimer(),
    this.wanderingTimer = game.time.events.add(1e3 * Math.random() + 1e3, this.changeWalkingType, this)
}
,
Enemy.prototype.destroyWanderingTimer = function() {
    null  != this.wanderingTimer && (game.time.events.remove(this.wanderingTimer),
    this.wanderingTimer = null )
}
,
Enemy.prototype.getPosition = function() {
    return this._position3D
}
,
Enemy.prototype.hitFrau = function() {
    this.currentState != Enemy.States.gothit && this.currentState != Enemy.States.gameover && (FrauenVsRefugees.SoundManager.play(this.punchSound, 100),
    Frau.singleton.receiveHit(this._position3D))
}
,
Enemy.prototype.setIdle = function() {
    this.currentState != Enemy.States.gameover && (this._position3D.y = 0,
    this.changeWalkingType())
}
,
Enemy.prototype.updatePosition = function() {
    this._position3D.x = Math.max(game.camera.view.x / FrauenVsRefugees.VIEW_WINDOW_SCALE, this._position3D.x),
    this._position3D.x = Math.min(FrauenVsRefugees.Game.singleton.getCurrentSectionBounds(), this._position3D.x),
    this._position3D.z = Math.max(-6, this._position3D.z),
    this._position3D.z = Math.min(48, this._position3D.z),
    this.x = this._position3D.x,
    this.y = FrauenVsRefugees.VIEW_CENTER_Y + 50 + this._position3D.z + this._position3D.y,
    this.z = this._position3D.z
}
,
Enemy.prototype.receiveHit = function(t, e) {
    if (this.destroyWanderingTimer(),
    this.currentState != Enemy.States.gothit && this.currentState != Enemy.States.gameOver && (this.scale.x = t,
    this.damage(.41).health > 0)) {
        if (e) {
            var i = this.game.add.tween(this._position3D).to({
                x: this._position3D.x + t * (80 + 20 * Math.random()),
                z: this._position3D.z + 40 * Math.random() - 20,
                y: this._position3D.y - 50
            }, 400, Phaser.Easing.Sinusoidal.Out)
              , a = this.game.add.tween(this._position3D).to({
                y: this._position3D.y
            }, 250, Phaser.Easing.Sinusoidal.In);
            i.chain(a),
            i.start(),
            this.kickHitSound.play(),
            this.updateState(Enemy.States.gotkick)
        } else
            this.updateState(Enemy.States.gothit),
            FrauenVsRefugees.SoundManager.play(this.hitSound, 100);
        FrauenVsRefugees.Game.singleton.enemyProgressBar.updateState(this)
    }
}
,
Enemy.prototype.update = function() {
    if (0 == this.canStartMoving) {
        if (!game.camera.view.contains(this.x * FrauenVsRefugees.VIEW_WINDOW_SCALE, 10))
            return;
        this.canStartMoving = !0,
        this.setIdle()
    }
    if (this.updatePosition(),
    this.shadow.width = this.width,
    this.shadow.alpha = .7 - this._position3D.y / -50,
    this.shadow.position.set(this.x, FrauenVsRefugees.VIEW_CENTER_Y + 50 + this._position3D.z),
    this.currentState != Enemy.States.gothit && (this.currentState == Enemy.States.wandering || this.currentState == Enemy.States.hunting)) {
        var t = Frau.singleton.getPosition()
          , e = t.x - this._position3D.x
          , i = t.z - this._position3D.z
          , a = 0 > e ? -1 : 1
          , s = 0 > i ? -1 : 1
          , n = Math.abs(e)
          , o = Math.abs(i);
        if (60 > n && 5 > o)
            return this.scale.set(-a, 1),
            void this.updateState(Enemy.States.punching);
        if (this.currentState == Enemy.States.wandering)
            return this._position3D.x += this.wanderingDirection.x,
            void (this._position3D.z += this.wanderingDirection.y);
        if (100 > n && (this._position3D.z += this.Speed.y * s),
        n >= 60 && (this._position3D.x += this.Speed.x * a),
        60 > n && 5 > o)
            return this.scale.set(-a, 1),
            void this.updateState(Enemy.States.punching);
        this.scale.set(-a, 1)
    }
}
,
Enemy.prototype.kill = function() {
    FrauenVsRefugees.Game.singleton.enemyProgressBar.updateState(this),
    this.updateState(Enemy.States.gameover)
}
,
Enemy.prototype.gameOver = function() {
    delete Enemy.enemies[this.name + this.id],
    this.destroy(),
    FrauenVsRefugees.Game.singleton.enemyProgressBar.hideIfObjectIsDead(this),
    this.shadow.destroy(),
    FrauenVsRefugees.Game.singleton.enemyDead()
}
,
Enemy.States = {
    gameover: -1,
    idle: 0,
    hunting: 1,
    punching: 2,
    gothit: 3,
    gotkick: 4,
    wandering: 5
},
Enemy.enemies = {};
var EnemyAkarab = function(t, e, i) {
    this.name = "Akarab",
    this.faceImage = 2,
    this.enemytype = "enemyAkarab",
    this.Speed = new Phaser.Point(1,1),
    this.WanderingSpeed = new Phaser.Point(1,1),
    Enemy.call(this, t, e, this.enemytype, i)
}